package zcjq.d831;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Matches {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = Integer.parseInt(scanner.nextLine());
        List<Long> savedList = new ArrayList<>();
        savedList.add(4l);
        for (int i = 0; i < T; i++) {
            // 火柴总数
            long n = Long.parseLong(scanner.nextLine());
            // 在火柴列表的索引, 火柴数比此多
            int idx = checkList(savedList, n);
            if (idx > 0 || n == 4) {
                int total = 0;
                int level = idx * 2 + 1;                // 大于此层
                total += level * level;
                int numOfSide = 2 * level + 1;          //
                // 剩余的
                long last = n - savedList.get(idx - 1);
                if (last > numOfSide) {
                    total += level;
                    last -= numOfSide;
                }
                // 处理剩余的
                for (i = 0; last > 2; i++) {
                    if (i == 0) {
                        last -= 3;
                    } else {
                        last -= 2;
                    }
                    total++;
                }


                System.out.println(last);
            } else {
                System.out.println(0);
            }
        }
    }

    private static int checkList(List<Long> savedList, long n) {
        while (savedList.get(savedList.size() - 1) < n) {
            long tmp = savedList.size() * 2 + 1;
            savedList.add(2 * tmp * (tmp + 1));
        }
        int idx = Collections.binarySearch(savedList, n);
        if (idx >= 0) {
            return idx;
        } else {
            return (-1 * idx - 1);
        }
    }
}
